package com.youku.utils
{
   import flash.utils.Dictionary;
   import flash.net.getClassByAlias;
   import flash.display.DisplayObject;
   import com.youku.baseUI.BasePlayerButton;
   import fl.controls.Button;
   import fl.controls.LabelButton;
   import flash.text.TextField;
   import flash.text.AntiAliasType;
   import com.youku.baseUI.YoukuTextField;
   
   public class AssetUtil extends Object
   {
      
      public function AssetUtil() {
         super();
      }
      
      private static var _classCache:Dictionary = new Dictionary();
      
      public static function getClassByAliasInternal(param1:String) : Class {
         var _loc2_:Class = null;
         if(_classCache.hasOwnProperty(param1))
         {
            return _classCache[param1];
         }
         _loc2_ = getClassByAlias(param1);
         if(_loc2_ != null)
         {
         }
         return _loc2_;
      }
      
      public static function getAsset(param1:String) : DisplayObject {
         var ClassReference:Class = null;
         var name:String = param1;
         try
         {
            ClassReference = getClassByAliasInternal(name);
            return new ClassReference();
         }
         catch(e:ReferenceError)
         {
            return null;
         }
         return null;
      }
      
      public static function getStyleButton(param1:String, param2:String = "", param3:String = null) : BasePlayerButton {
         var _loc4_:BasePlayerButton = new BasePlayerButton();
         _loc4_.label = param2;
         _loc4_.buttonMode = true;
         _loc4_.useHandCursor = true;
         setButtonSkin(_loc4_,param1);
         return _loc4_;
      }
      
      public static function setButtonSkin(param1:Button, param2:String) : void {
         try
         {
            param1.setStyle("upSkin",getAsset(param2 + "_up"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("overSkin",getAsset(param2 + "_over"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("downSkin",getAsset(param2 + "_down"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("disabledSkin",getAsset(param2 + "_disable"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("selectedUpSkin",getAsset(param2 + "_selected_up"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("selectedOverSkin",getAsset(param2 + "_selected_over"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("selectedDownSkin",getAsset(param2 + "_selected_down"));
         }
         catch(e:*)
         {
         }
         try
         {
            param1.setStyle("selectedDisabledSkin",getAsset(param2 + "_selected_disable"));
         }
         catch(e:*)
         {
         }
      }
      
      public static function restoreButtonSize(param1:LabelButton) : void {
         var _loc2_:Number = 0;
         var _loc3_:Number = 0;
         if(param1.getStyle("upSkin") != null)
         {
            _loc2_ = DisplayObject(param1.getStyle("upSkin")).width;
            _loc3_ = DisplayObject(param1.getStyle("upSkin")).height;
         }
         _loc2_ = Math.ceil(_loc2_);
         _loc3_ = Math.ceil(_loc3_);
         param1.setSize(_loc2_,_loc3_);
         param1.validateNow();
      }
      
      public static function setIcons(param1:Button, param2:String = null, param3:String = null, param4:String = null, param5:String = null) : void {
         if(param2 != null)
         {
            param1.setStyle("upIcon",getAsset(param2));
         }
         if(param3 != null)
         {
            param1.setStyle("overIcon",getAsset(param3));
         }
         if(param4 != null)
         {
            param1.setStyle("downIcon",getAsset(param4));
         }
         if(param5 != null)
         {
            param1.setStyle("disabledIcon",getAsset(param5));
         }
      }
      
      public static function autoSizeButton(param1:LabelButton, param2:Number = -1) : void {
         if(param2 == -1)
         {
            param2 = 5;
         }
         param1.setStyle("textPadding",param2);
         param1.setSize(300,100);
         param1.validateNow();
         var _loc3_:Number = 0;
         var _loc4_:Number = 0;
         if(!(param1.getStyle("upIcon") == null) && !(param1.label == ""))
         {
            _loc3_ = DisplayObject(param1.getStyle("upIcon")).width + param1.textField.textWidth + 8 + param2;
            _loc4_ = Math.max(DisplayObject(param1.getStyle("upIcon")).height + param2 * 2,param1.textField.textHeight + 4);
         }
         else if(param1.getStyle("upIcon") != null)
         {
            _loc3_ = DisplayObject(param1.getStyle("upIcon")).width;
            _loc4_ = DisplayObject(param1.getStyle("upIcon")).height + param2 * 2;
         }
         else if(param1.label != "")
         {
            _loc3_ = param1.textField.textWidth + 8;
            _loc4_ = param1.textField.textHeight + 4;
         }
         
         
         _loc3_ = Math.ceil(_loc3_);
         _loc4_ = Math.ceil(_loc4_);
         param1.setSize(_loc3_ + param2 * 2,_loc4_);
         param1.validateNow();
      }
      
      public static function getTextField(param1:Boolean = true) : TextField {
         var _loc2_:TextField = new TextField();
         _loc2_.antiAliasType = AntiAliasType.ADVANCED;
         _loc2_.cacheAsBitmap = true;
         _loc2_.selectable = false;
         _loc2_.wordWrap = param1;
         _loc2_.multiline = param1;
         return _loc2_;
      }
      
      public static function getYoukuTextField(param1:Boolean = true) : YoukuTextField {
         var _loc2_:YoukuTextField = new YoukuTextField();
         _loc2_.antiAliasType = AntiAliasType.ADVANCED;
         _loc2_.cacheAsBitmap = true;
         _loc2_.selectable = false;
         _loc2_.wordWrap = param1;
         _loc2_.multiline = param1;
         return _loc2_;
      }
   }
}
